﻿using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XH.SmartParking.IService;
using XH.SmartParking.Entities;

namespace XH.SmartParking.Service
{
    public class RechargeSerivce : BaseService, IRechargeService
    {
        public RechargeSerivce(DbContext context) : base(context)
        {
        }

        public IEnumerable<MemberRecharge> GetRecharges(string skey, int pageSize, int pageIndex, out int totalCount)
        {
            var pResult = QueryPage<MemberRecharge, string>(
                    q => string.IsNullOrEmpty(skey) ||
                        q.AutoLisence.Contains(skey),

                    pageSize,
                    pageIndex,
                    order => order.AutoLisence,
                    false
                );

            totalCount = pResult.TotalCount;

            return from q in pResult.DataList
                   join fm in Set<BaseFeeMode>() on q.FeeModeId equals fm.FeeModeId
                   select new MemberRecharge
                   {
                       RId = q.RId,
                       AutoLisence = q.AutoLisence,
                       FeeModeId = fm.FeeModeId,
                       FeeModeName = fm.FeeModeName,
                       RechargeCount = q.RechargeCount,
                       RechargeEndTime = q.RechargeEndTime,
                       RechargeStartTime = q.RechargeStartTime,
                       CreateId = q.CreateId,
                       CreateName = q.CreateName,
                       CreateTime = q.CreateTime,
                       State = q.State
                   };
        }
    }
}
